Vue.filter('formatterBLevel', function (value) {
    switch (value) {
        case "0":
            return "国标";
            break;
        case "1":
            return "省标";
            break;
        case "2":
            return "市标";
             break;
                    default:
                        return "县标";
                }
            });



Vue.filter('formatterTime', function (value) { // 时间戳转时间
    let date = new Date(value);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    Y = date.getFullYear() + '-';
    M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    D = date.getDate() + ' ';
    h = date.getHours() + ':';
    m = date.getMinutes() + ':';
    s = date.getSeconds();
    return Y + M + D;
})
var vm = new Vue({
    el: '#rrapp',
    data: {
        secondActive:0,
        centerActive:0,
        rightActive:0,
        delSecondActive:-1,
        activeName: "0",
        dialogFormVisible: false, form: {
            name: '',
            region: '',
            date1: '',
            date2: '',
            delivery: false,
            type: [],
            resource: '',
            desc: ''
        },
        dialogFormSearch: false, formSearch: {
            name: ''
        },
        dialogFormDetail: false,
        formDetail: {},
        /*formLabelWidth: '83px',*/

        showList: true,
        title: null,
        switchValue: true,
        firstKindData: [], // 大类
        secondKindData: [], // 小类
        centerKindData: [], // 子类
        rightKindData: [], // 检查项
        secondKindDetail: {}, // 小类详情

        addFirstKindDetailData: {},
        firstKindSubmitForm: {
            levelNum: '1',
            questionDescription: '',
            isGenerateStandardTemplate: '0',
            parentId: '0'
        },
        addSecondKindDetailData: {}, // 添加小类时详情数据
        secondKindSubmitForm: { // 小类提交表单
            levelNum: '2',
            questionDescription: '',
            isGenerateStandardTemplate: '0',
            parentId: '',
            yjmldm: '',
            yjmlmc: ''
        },
        centerKindDetailData: {}, // 子类详情
        addCenterKindDetailData: {}, // 添加子类时详情数据
        centerKindSubmitForm: { // 子类提交表单
            levelNum: '3',
            questionDescription: '',
            isGenerateStandardTemplate: '0',
            yjmldm: '',
            yjmlmc: '',
            parentId: '',
            ejmldm: '',
            ejmlmc: ''
        },
        rightKindDetailData: {}, // 检查项详情
        addRightKindDetailData: {}, // 添加检查项时详情数据
        rightCountData: {}, // 检查项时详情统计数据
        rightKindSubmitForm: { // 检查项提交表单
            levelNum: '4',
            questionDescription: '',
            isGenerateStandardTemplate: '0',
            yjmldm: '',
            yjmlmc: '',
            ejmldm: '',
            ejmlmc: '',
            sjmldm: '',
            parentId: '',
            sjmlmc: ''
        },
        firstIndex: 0,
        secondIndex: 0,
        centerIndex: 0,
        rightIndex: 0,
        firstAddShowFlag: false,// 添加大类表单显隐
        secondAddShowFlag: false, // 添加小类表单显隐
        centerAddShowFlag: false, // 添加子类表单显隐
        rightAddShowFlag: false, // 添加检查项表单显隐
        rightDetailShowFlag: false // 查看检查项详情显隐

    },
    mounted() {
        this.getlistData();
        this.getAddFirstData();
    },
    methods: {
        handleClick: function (tab) {
            vm.selectFirstKind(tab.name)
            // alert(tab.name);

        },
        getlistData: function () {
            let url = 'business/supervisestandard/findAllList'
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                success: function (res) {
                    if (res.code === '0') {
                        vm.firstKindData = res.superviseStandard // 获得大类
                        vm.buildDataList(vm.firstKindData)


                    } else {
                        alert(res.msg);
                    }
                }
            });
        },
        // 获得检查项详情
        getRightDetailsData: function (index) {
            vm.rightKindDetailData = vm.rightKindData[index]
            vm.getDptData(vm.rightKindDetailData.deptId)
            vm.getRightCountData();
            vm.rightDetailShowFlag = true
        },
        getRightListData: function () {
            
            let url = 'business/supervisestandard/findListByParentId'
            $.ajax({
                type: "POST",
                url: baseURL + url,
                data: {
                    parentId: vm.centerKindData[vm.centerIndex].id
                },
                success: function (res) {
                    if (res.code === '0') {
                        vm.rightKindData = res.list; // 获得检查项
                        if (vm.rightKindData[vm.rightIndex] == undefined) {
                            vm.rightIndex = 0
                        }
                        vm.rightKindDetailData = vm.rightKindData[vm.rightIndex]
                        if (vm.rightKindData.length > 0) {
                            if (vm.rightKindDetailData.deptId != null) {
                                vm.getDptData(vm.rightKindDetailData.deptId)
                            }
                            vm.rightDetailShowFlag = false
                            // vm.getRightCountData();
                        } else {
                            vm.rightDetailShowFlag = false
                        }

                    } else {
                        alert(res.msg);
                    }
                }
            });
        },
        // 组装各级数据的数组
        buildDataList: function (firstKindData) {
            if (firstKindData.length > 0) {
                vm.secondKindData = vm.firstKindData[vm.firstIndex].children
                vm.secondKindDetailData = vm.secondKindData[vm.secondIndex]
            } else {
                vm.firstKindData = []
                vm.secondKindData = []
                vm.centerKindData = []
                vm.rightKindData = []
            }

            if (vm.secondKindData.length > 0) {
                vm.centerKindData = vm.secondKindData[vm.secondIndex].children
                vm.centerKindDetailData = vm.centerKindData[vm.centerIndex]
            } else {
                vm.secondKindData = []
                vm.centerKindData = []
                vm.rightKindData = []
            }
            if (vm.centerKindData.length > 0) {
                // vm.rightKindData = vm.centerKindData[vm.centerIndex].children
                // vm.rightKindDetailData = vm.rightKindData[vm.rightIndex]
                vm.getRightListData();
            } else {
                vm.centerKindData = []
                vm.rightKindData = []
            }


        },
        // 获得单位信息
        getDptData: function (deptId) {
            let url = 'sys/dept/info2/' + deptId
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                success: function (res) {
                    if (res.code === '0') {
                        vm.rightKindDetailData.depName = res.dept.name
                    } else {
                        alert(res.msg);
                    }
                }
            });
        },
        // 新增大类项信息
        getAddFirstKindData: function () {

            pageii = layer.open({
                title: "新增",
                type: 2,
                shadeClose: true,
                fixed: true,
                area: ["550px", "400px"],
                content: baseURL + 'modules/business/standardAdd.html'
            });
        },
        // 获得新增小类项信息
        getAddSecondData: function () {
            let url = 'business/supervisestandard/getNextObjectInfo';
            if (vm.firstKindData.length > 0) {
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    data: {
                        level: 2, code: vm.firstKindData[vm.firstIndex].sbdm
                    },
                    // contentType: "application/json",
                    success: function (res) {
                        if (res.code === '0') {
                            vm.addSecondKindDetailData = res.superviseStandard;
                        } else {
                            alert(res.msg);
                        }
                    }
                });
            } else {
                alert('无大类，请先新增大类！')
            }

        },
        // 获得新增子类信息 "3", vm.secondKindData[vm.secondIndex].sbdm, vm.addCenterKindDetailData
        getAddCenterData: function (level, code, data) {
            let url = 'business/supervisestandard/getNextObjectInfo';
            if (vm.secondKindData.length > 0) {
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    data: {
                        level: 3, code: vm.secondKindData[vm.secondIndex].sbdm
                    },
                    // contentType: "application/json",
                    success: function (res) {
                        if (res.code === '0') {
                            vm.addCenterKindDetailData = res.superviseStandard;
                        } else {
                            alert(res.msg);
                        }
                    }
                });
            } else {
                alert('无子类，请先新增子类！')
            }

        },
        // 获得检查新增项信息 level, code, data
        getAddRightData: function () {
            let url = 'business/supervisestandard/getNextObjectInfo';
            if (vm.centerKindData.length > 0) {
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    data: {
                        level: 4, code: vm.centerKindData[vm.centerIndex].sbdm
                    },
                    // contentType: "application/json",
                    success: function (res) {
                        if (res.code === '0') {
                            vm.addRightKindDetailData = res.superviseStandard;
                        } else {
                            alert(res.msg);
                        }
                    }
                });
            } else {
                alert('无检查项，请先新增检查项！')
            }

        },
        // 获得问题统计信息信息 level, code, data
        getRightCountData: function () {
            let url = 'business/supervisestandard/getQuestionCount';
            if (vm.rightKindData.length > 0) {
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    data: {
                        standardId: vm.rightKindDetailData.id
                    },
                    // contentType: "application/json",
                    success: function (res) {
                        if (res.code === '0') {
                            if (res.countMap.questionNum != null && res.countMap.questionNum != undefined && res.countMap.questionNum != "") {
                                res.countMap.incidenceTate = Number(res.countMap.questionNum * 100 / res.countMap.allNum).toFixed(2);
                                res.countMap.repetitionRate = Number(res.countMap.repeatNumN * 100 / res.countMap.questionNum).toFixed(2);
                            } else {
                                res.countMap.incidenceTate = 0;
                                res.countMap.repetitionRate = 0;
                            }

                            vm.rightCountData = res.countMap;
                        } else {
                            alert(res.msg);
                        }
                    }
                });
            } else {
                alert('无问题统计信息！')
            }
        },
        // 添加检查项
        addRightKind: function () {
            vm.getAddRightData();
            vm.rightAddShowFlag = true
            vm.rightKindSubmitForm.questionDescription = ''
            vm.rightDetailShowFlag = false
        },
        // 关闭检查项添加表单
        cancelJcxAdd: function () {
            vm.rightAddShowFlag = false
            vm.rightKindSubmitForm.questionDescription = ''
        },
        // 添加子类
        addCenterKind: function () {
            vm.getAddCenterData();
            vm.centerAddShowFlag = true
            vm.centerKindSubmitForm.questionDescription = ''
        },
        // 关闭子类添加表单
        cancelCenterAdd: function () {
            vm.centerAddShowFlag = false
            vm.centerKindSubmitForm.questionDescription = ''
        },
        // 添加小类
        addSecondKind: function () {
            vm.getAddSecondData();
            vm.secondAddShowFlag = true
            vm.secondKindSubmitForm.questionDescription = ''
        },
        // 关闭小类添加表单
        cancelSecondAdd: function () {
            vm.secondAddShowFlag = false
            vm.secondKindSubmitForm.questionDescription = ''
        },
        // 选择大类
        selectFirstKind: function (index) {
            debugger
            $('.first-kind-list').on('click', 'li', function () {
                $(this).siblings().removeClass('active')
                $(this).addClass('active')
            })
            vm.firstIndex = parseInt(index)
            vm.secondIndex = 0
            vm.centerIndex = 0
            vm.rightIndex = 0
            vm.secondKindData = vm.firstKindData[vm.firstIndex].children
            vm.centerKindData = vm.secondKindData[vm.secondIndex].children
            vm.rightKindData = vm.centerKindData[vm.centerIndex]
            vm.buildDataList(vm.firstKindData)
            // vm.getlistData()
        },
        // 选择子类
        selectSecondKind: function (index) {
            $('.second-kind-list').on('click', 'li', function () {
                $(this).siblings().removeClass('active')
                $(this).addClass('active')
            });
            this.secondActive = index;
            this.centerActive = 0;
            this.rightActive = 0;
            vm.secondIndex = parseInt(index)
            vm.centerIndex = 0
            vm.rightIndex = 0
            vm.centerKindData = vm.secondKindData[vm.secondIndex].children
            vm.rightKindData = vm.centerKindData[vm.centerIndex]
            vm.buildDataList(vm.firstKindData)
            // vm.getlistData()
        },
        // 选择小类
        selectCenterKind: function (index) {
            $('.center-kind-list').on('click', 'li', function () {
                $(this).siblings().removeClass('active')
                $(this).addClass('active')
            });
            this.centerActive = index;
            this.rightActive = 0;
            vm.centerIndex = parseInt(index)
            vm.rightIndex = 0;
            vm.rightKindData = vm.centerKindData[vm.centerIndex]
            vm.buildDataList(vm.firstKindData)
            // vm.getlistData()
        },
        // 选择检查项
        selectRightKind: function (index) {
            $('.right-kind-list').on('click', 'li', function () {
                $(this).siblings().removeClass('active')
                $(this).addClass('active')
            })
            this.rightActive = index;
            /*vm.rightIndex = parseInt(index)
            vm.buildDataList(vm.firstKindData)*/
            // vm.getRightCountData();
        },
        delRight:function(index){
            this.delSecondActive = index;
        },
        // 时间转时间戳
        getUnix: function () {
            let unix = Date.parse(new Date())
        },

        //取消
        cancelFirstAdd: function () {
            vm.firstAddShowFlag = false
        },
        saveFirstKind: function () {
            layer.confirm("是否确定添加大类？", function (index) {
                let url = 'business/supervisestandard/save';
                let params = vm.firstKindSubmitForm;
                // params.isGenerateStandardTemplate = 1;//是否生成标准模板 0 不生成 1 生成， 做个操作
                // params.deptId = vm.rightKindDetailData.deptId
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(params),
                    success: function (res) {

                        if (res.code === '0') {
                            //请求成功刷新页面数据
                            vm.getlistData();
                            vm.hideAll();
                        } else {
                            alert(res.msg);
                        }
                        layer.close(index);
                        layer.close(index);
                    }
                });
            });
        },
        getAddFirstData: function () {
            let url = 'business/supervisestandard/getNextObjectInfo';
            $.ajax({
                type: "POST",
                url: baseURL + url,
                data: {
                    level: 1
                },
                // contentType: "application/json",
                success: function (res) {
                    if (res.code === '0') {
                        vm.addFirstKindDetailData = res.superviseStandard;
                    } else {
                        alert(res.msg);
                    }
                }
            });
        },
        // 删除检查项
        deleteRightKind: function (value) {
            layer.confirm("是否确定删除该检查项？", function (index) {
                let id = vm.rightKindDetailData.id;
                let url = 'business/supervisestandard/delete?id=' + id;

                $.ajax({
                    type: "GET",
                    url: baseURL + url,
                    // contentType: "application/json",
                    // data: JSON.stringify(id),
                    success: function (res) {
                        if (res.code === '0') {
                            //请求成功刷新页面数据
                            vm.getlistData()
                        } else {
                            alert(res.msg);
                        }
                        layer.close(index);
                    }
                });
            });

        },
        // 确定添加小类
        saveSecondKind: function () {
            layer.confirm("是否确定添加该类别？", function (index) {
                let url = 'business/supervisestandard/save';
                let params = vm.secondKindSubmitForm;
                params.parentId = vm.firstKindData[vm.firstIndex].id;
                params.yjmldm = vm.firstKindData[vm.firstIndex].sbdm;
                params.yjmlmc = vm.firstKindData[vm.firstIndex].questionDescription;
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(params),
                    success: function (res) {
                        if (res.code === '0') {
                            //请求成功刷新页面数据
                            vm.getlistData()
                            vm.hideAll()
                        } else {
                            alert(res.msg);
                        }
                        layer.close(index);
                    }
                });
            });
        },
        // 确定添加子类
        saveCenterKind: function () {
            layer.confirm("是否确定添加该类别？", function (index) {
                let url = 'business/supervisestandard/save';
                let params = vm.centerKindSubmitForm;
                params.yjmldm = vm.firstKindData[vm.firstIndex].sbdm;
                params.yjmlmc = vm.firstKindData[vm.firstIndex].questionDescription;
                params.parentId = vm.secondKindData[vm.secondIndex].id;
                params.ejmldm = vm.secondKindData[vm.secondIndex].sbdm;
                params.ejmlmc = vm.secondKindData[vm.secondIndex].questionDescription;
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(params),
                    success: function (res) {
                        if (res.code === '0') {
                            //请求成功刷新页面数据
                            vm.getlistData()
                            vm.hideAll()
                        } else {
                            alert(res.msg);
                        }
                        layer.close(index);
                    }
                });
            });
        },
        // 确定添加检查项
        saveRightKind: function () {
            layer.confirm("是否确定添加检查项？", function (index) {
                let url = 'business/supervisestandard/save';
                let params = vm.rightKindSubmitForm;
                params.yjmldm = vm.firstKindData[vm.firstIndex].sbdm;
                params.yjmlmc = vm.firstKindData[vm.firstIndex].questionDescription;
                params.ejmldm = vm.secondKindData[vm.secondIndex].sbdm;
                params.ejmlmc = vm.secondKindData[vm.secondIndex].questionDescription;
                params.parentId = vm.centerKindData[vm.centerIndex].id;
                params.sjmldm = vm.centerKindData[vm.centerIndex].sbdm;
                params.sjmlmc = vm.centerKindData[vm.centerIndex].questionDescription;
                // params.isGenerateStandardTemplate = 1;//是否生成标准模板 0 不生成 1 生成， 做个操作
                // params.deptId = vm.rightKindDetailData.deptId
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(params),
                    success: function (res) {

                        if (res.code === '0') {
                            //请求成功刷新页面数据
                            vm.getlistData();
                            vm.hideAll();
                        } else {
                            alert(res.msg);
                        }
                        layer.close(index);
                    }
                });
            });
        },
        // 检测新增时内容变化厚的值
        getRightContent: function () {
            console.log(vm.centerKindSubmitForm.questionDescription)
            console.log(vm.rightKindSubmitForm.questionDescription)
        },
        // 添加成功后隐藏所有新增框
        hideAll: function () {

            vm.firstAddShowFlag = false
            vm.secondAddShowFlag = false
            vm.centerAddShowFlag = false
            vm.rightAddShowFlag = false
            vm.rightDetailShowFlag = false
        },
        // 是否更新模板
        updateTpl: function (type) {
            switch (type) {
                case '1':
                    vm.secondKindSubmitForm.isGenerateStandardTemplate = parseInt(vm.secondKindSubmitForm.isGenerateStandardTemplate) === 1 ? '0' : '1'
                    console.log(vm.secondKindSubmitForm.isGenerateStandardTemplate)
                    break
                case '2':
                    vm.centerKindSubmitForm.isGenerateStandardTemplate = parseInt(vm.centerKindSubmitForm.isGenerateStandardTemplate) === 1 ? '0' : '1'
                    console.log(vm.centerKindSubmitForm.isGenerateStandardTemplate)
                    break
                default:
                    vm.rightKindSubmitForm.isGenerateStandardTemplate = parseInt(vm.rightKindSubmitForm.isGenerateStandardTemplate) === 1 ? '0' : '1'
                    console.log(vm.rightKindSubmitForm.isGenerateStandardTemplate)
            }
        }

    }
});
$(function () {
    $(".bzwt-dcjg li").on("click",function(){
        alert(2222);
    });
    $(".bzwt-dcjg li").click(function () {
        alert(11);
        $(".bzwt-dcjg li").removeClass("bzwtLiChoose");
        $(".bzwt-dcjg li").children("span").hide().removeClass("spanDel");
        $(this).addClass("bzwtLiChoose");
        $(this).children("span").show().addClass("spanDel");
        $(this).find("bzwt-sb").addClass("bzwt-sbChoose");
    });
    $(".bzwt-dcjg li>span").click(function () {
        $(this).parent().remove();
    });
});